package com.itheima.exce;

import java.util.InputMismatchException;
import java.util.Scanner;

public class ExceptionDemo4 {
    public static void main(String[] args) {
        Student student = new Student();
        System.out.println("请输入姓名");
        Scanner sc = new Scanner(System.in);
        String name = sc.nextLine();
        student.setName(name);

        while (true) {
            System.out.println("请输入年龄");
            try {
                String ageStr = sc.nextLine();
                int age = Integer.parseInt(ageStr);
                student.setAge(age);
                break;
            } catch (NumberFormatException e) {
                System.out.println("请输入一个整数");
                continue;
            } catch (RuntimeException e) {
                System.out.println("请输入符合范围的年龄");
                continue;
            }
        }
        System.out.println(student);
    }
}

